package radubrehar;



import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.collection.PersistentList;

import radubrehar.util.HibernateUtil;

public class Main {
	public static void main(String[] args) {
		try {
			
			SessionFactory factory = HibernateUtil.getSessionFactory();
			Session session = factory.openSession();
			
			Transaction tr = session.beginTransaction();
			
//			UserSession userSession = new UserSession();
//			
//			userSession.setSessionId("mysessionid");
//			
			
//			
////			userSession.setLinks(links);
//			
//			session.saveOrUpdate(userSession);
			
			List<UserSession> userSession = session.createQuery("from UserSession where sessionId='mysessionid'").list();
			
			for (UserSession us : userSession) {
				System.out.println("user session " + us.getSessionId());
			}
			
			UserSessionLink link1 = new UserSessionLink();
			link1.setURL("http://www.google.ro");
			
			userSession.get(0).addLink(link1);
			
			session.saveOrUpdate(userSession.get(0));
			
			tr.commit();
			
			System.out.println("OK");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
